<?php

namespace front\modules\app\controllers;

use Yii;
use front\models\LogisticsmsgModel;
use yii\data\ActiveDataProvider;
use front\controllers\WebBaseController;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use messages\services\LogisticService;
use yii\helpers\ArrayHelper;

/**
 * LogisticsmsgController implements the CRUD actions for LogisticsmsgModel model.
 */
class LogisticsmsgController extends WebBaseController
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    /**
     * Lists all LogisticsmsgModel models.
     * @return mixed
     */
    public function actionIndex()
    {
       $data = yii::$app->request->get();
       $data['customer_id'] = $this->user_id;
       $info = LogisticService::search($data);
       $info['result'] = ArrayHelper::toArray($info['result']);
       $info['result']['list'] = array_map(function($v){
           $v['created_at'] = date('Y-m-d H:i',$v['created_at']);
           return $v;
       },$info['result']['list']);
       if($info['code']==1){
           WebBaseController::getAjaxData(2,'获取错误');
       }
        WebBaseController::getAjaxData(1,'获取成功',$info['result']);
    }
    /**
     * Creates a new LogisticsmsgModel model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new LogisticsmsgModel();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Updates an existing LogisticsmsgModel model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

    /**
     * Deletes an existing LogisticsmsgModel model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the LogisticsmsgModel model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return LogisticsmsgModel the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = LogisticsmsgModel::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
